<?php
    class xuatxudb
    {
        public $_tablename = "giaphucvn_xuatxu";
        public function getList($MaXuatXu = 0, $TenXuatXu = '', $order = '', $start = 0, $num = 30, $all = 0)
		{
			$sql = "SELECT * FROM ".$this->_tablename." WHERE (1)";
			
			if ($MaXuatXu != 0)
				$sql .= " AND MaXuatXu = " . dataservice::QuoteSmart($MaXuatXu);
			
			if ($TenXuatXu != '')
				$sql .= " AND TenXuatXu LIKE " . dataservice::QuoteSmart('%' . $TenXuatXu . '%');
			
			if ($order != '')
				$sql .= " ORDER BY " . $order . " DESC";
			
			if($all == 0)
				$sql .= " LIMIT " . $start . ", ".$num;
			//echo $sql;
			$db = new dataservice();
			$ret = $db->ExecuteQuery($sql);
			return $ret;
		}
        
        public function add($TenXuatXu = '')
		{
			$sql = "INSERT INTO ".$this->_tablename."(TenXuatXu) VALUES(" . dataservice::QuoteSmart($TenXuatXu) . ")";
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function update($MaXuatXu = 0, $TenXuatXu = '')
		{
			$sql = "UPDATE ".$this->_tablename." SET TenXuatXu = " . dataservice::QuoteSmart($TenXuatXu) . " WHERE MaXuatXu = ".dataservice::QuoteSmart($MaXuatXu);
			//echo $sql;
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function delete($MaXuatXu = 0)
		{
			$sql = "DELETE FROM ".$this->_tablename." WHERE (1)";
			
			if ($MaXuatXu != 0)
				$sql .= " AND MaXuatXu = " . dataservice::QuoteSmart($MaXuatXu);
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
        
        public function issetTypes($MaXuatXu = 0, $TenXuatXu = "")
		{
			$sql = "SELECT COUNT(*) AS SoDong FROM ".$this->_tablename." WHERE (1)";
            
            if($MaXuatXu != 0)
				$sql .= " AND MaXuatXu = $MaXuatXu";
            
			if($TenXuatXu != "")
				$sql .= " OR TenXuatXu = '$TenXuatXu'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
        
        public function issetType($TenXuatXu = "")
		{
			$sql = "SELECT COUNT(*) AS SoDong FROM ".$this->_tablename." WHERE (1)";
			if($TenXuatXu != "")
				$sql .= " AND TenXuatXu = '$TenXuatXu'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
    }
?>